/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *    2010 year
 *    Author: Michael Khromov aka MikeDM (Mike D'Morto)
 *    E-Mail: mikedm@list.ru
 */

#include <QtDebug>
#include "mconfig.h"
#include "def.h"

mconfig::mconfig(QObject *parent) :
    QObject(parent)
{
    // clear all data
    this->clear();
}

void mconfig::clear(){
    // clear data
    server="";
    serverkey="";
    login="";
    password="";
    botname="";
    ignoressl=false;
    ignorecache=false;
    cache_dir="";
    log_dir="";
    debug_level=0;
    tik=0;
    death_time=-1;
}

bool mconfig::loadConfig(const QString & fname){
    // load config
    this->clear();
    this->cfgfile=fname;
    this->inconf = new QSettings(this->cfgfile,QSettings::IniFormat);
    // test cfg version
    QString ver=inconf->value("main/version").toString();
    if( ver != d_cfgver){
        return false;
    }
    this->server=inconf->value("main/server").toString();
    this->s_path=inconf->value("main/s_path").toString();
    // set proto
    this->proto=inconf->value("main/proto","https").toString();
    if(this->proto != "https" || this->proto != "http"){
        this->proto="https";
    }

    this->serverkey=inconf->value("main/serverkey").toString();
    this->login=inconf->value("main/login").toString();
    this->password=inconf->value("main/password").toString();
    this->botname=inconf->value("main/botname").toString();
    this->ignoressl=inconf->value("main/ignoressl","false").toBool();
    this->cache_dir=inconf->value("main/cache_dir").toString();
    this->ignorecache=inconf->value("main/ignorecache","false").toBool();
    this->log_dir=inconf->value("main/log_dir").toString();
    this->debug_level=inconf->value("main/debug_level","0").toInt();
    this->tik=inconf->value("main/tik","300").toInt();
    this->death_time=inconf->value("main/death_time","-1").toInt();

    return true;
}
